﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using GBIT.Web;
using WebComponents;
using WebComponents.Security;
using WebComponents.Data;

public partial class ThemMoiColor : UserControlBase {
  int colorId = -1;
  protected void Page_Load(object sender, EventArgs e) {
    ImagePath.RequiredFieldValidator = true;
    colorId = ConvertType.ToInt(Request.Params["id"]);
    this.Title = "Màu sắc sản phẩm";
    this.TaskTitle = "Thêm mới";
    if (!IsPostBack) {
      LoadAlbum();
    }
    if (colorId > 0) {
      if (!IsPostBack) {
        LoadFileByFileID(colorId);
        this.TaskTitle = "Cập nhật";
      }
    } 
    this.SaveEnabled = true;
  }
  protected void LoadAlbum() {
    this.cmbAlbum.Items.Clear();
    this.cmbAlbum.Items.Add("");
    Global.LoadCategory("vi-VN", ref cmbAlbum, CatetoryType.Color);  
  }
  protected void LoadFileByFileID(int FileID) {
    ColorInfo obj = ColorController.GetByColorID(FileID);
    txtTitle.Text = obj.ColorName;   
    ImagePath.ImagePath = obj.ColorImage;
    ImagePath.ImageUrl = obj.ColorImage;
  }
  protected override void OnSaveRecord(bool redirect) {
    ColorInfo obj = null;
    if (colorId > 0)
      obj = ColorController.GetByColorID(colorId);
    if (obj == null)
      obj = new ColorInfo();
    obj.ColorName = txtTitle.Text.Trim();
    obj.CateID = ToInt(cmbAlbum.SelectedValue);   
    obj.ColorImage = ImagePath.ImagePath;   
    if (colorId > 0) {
      ColorController.Update(obj);
    } else {
      ColorController.Insert(obj);
    }
//    Security.ShowClientMessage(Page, "Lưu trữ thông tin màu sắc sản phẩm thành công!", string.Format("?mod={0}", WebComponents.ConvertType.Encode("Color/ColorList.ascx")));
  }
}
